﻿<KCtl:BasePhoneApplicationPage 
    x:Class="Kiva7.MainPage"
    xmlns:KCtl="clr-namespace:Kiva7.Controls"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="728" 
    xmlns:my="clr-namespace:Kiva7.Pages" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="PortraitOrLandscape"  
    Orientation="Portrait"
    Loaded="MainPageLoaded" 
    ImageData="{Binding Lender.Image}">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid>
            <Grid Visibility="{Binding Converter={StaticResource objectVisibility}}">
                <TextBlock x:Name="Error" 
                       Text="{Binding Path=L.SorryCantConnect, Source={StaticResource L}}" 
                       TextAlignment="Center"
                       TextWrapping="Wrap"
                       Visibility="{Binding HasError, Converter={StaticResource booleanToVisibility}}" 
                       HorizontalAlignment="Center" 
                       VerticalAlignment="Center" />
            </Grid>
            <Button x:Name="AccountCreation" Visibility="Collapsed" Click="FirstStartPageClick"
                HorizontalAlignment="Center" VerticalAlignment="Center"
                    Style="{StaticResource KivaButtonStyle}">
                <TextBlock Text="{Binding Path=L.PleaseRegisterFirst, Source={StaticResource L}}"
                       TextWrapping="Wrap">

                </TextBlock>
            </Button>


            <!--Pivot Control-->

            <KCtl:OrientedPivot x:Name="Pivot" Title="{Binding Lender.Name}"
                        Visibility="{Binding HasError, Converter={StaticResource booleanToNotVisibility}}" 
                        LoadingPivotItem="Pivot_LoadingPivotItem" Template="{StaticResource PivotControlTemplateLandscape}" >
                <KCtl:OrientedPivot.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid></Grid>
                    </ItemsPanelTemplate>
                </KCtl:OrientedPivot.ItemsPanel>

                <controls:PivotItem x:Name="pvLender" Header="{Binding Path=L.Lender, Source={StaticResource L}}">
                    <my:MainLenderControl x:Name="MainLenderControl1" 
                                          DataContext="{Binding Lender}" />
                </controls:PivotItem>

                <controls:PivotItem x:Name="pvLoans" Header="{Binding Path=L.Portfolio, Source={StaticResource L}}" >
                    <Grid>
                        <KCtl:OrientedGrid Visibility="{Binding Lender.LoanCount, Converter={StaticResource numberVisibility}}">
                            <my:LoansControl x:Name="loansControl1" 
                                             DataContext="{Binding Loans}"
                                             KCtl:OrientedGrid.VisibilityL="Collapsed" 
                                             KCtl:OrientedGrid.VisibilityP="Visible" />
                            <my:LoansAndDetailControl x:Name="loansAndDetailControl1" 
                                             DataContext="{Binding Loans}"
                                             KCtl:OrientedGrid.VisibilityL="Visible" 
                                             KCtl:OrientedGrid.VisibilityP="Collapsed" />
                        </KCtl:OrientedGrid>

                        <my:NoLoansControl x:Name="noLoansControl1" 
                                     Visibility="{Binding Lender.LoanCount, Converter={StaticResource numberNotVisibility}}"/>
                    </Grid>
                </controls:PivotItem>

                <controls:PivotItem x:Name="pvFriends" Header="{Binding Path=L.Friends, Source={StaticResource L}}">
                    <my:FriendsControl x:Name="friendsControl1" Grid.Row="1"  />
                </controls:PivotItem>

                <controls:PivotItem Header="{Binding Path=L.Journal, Source={StaticResource L}}" x:Name="Journal">
                    <Grid>
                        <my:JournalEntriesControl x:Name="journalEntriesControl" DataContext="{Binding JournalEntries}" />
                    </Grid>
                </controls:PivotItem>

                <controls:PivotItem x:Name="pvTeams" Header="{Binding Path=L.Team, Source={StaticResource L}}">
                    <Grid>
                        <my:TeamsControl x:Name="teamsControl1" DataContext="{Binding Teams}"  />
                        <my:NoTeamsControl x:Name="noTeamsControl1"  DataContext="{Binding Teams}" />
                    </Grid>
                </controls:PivotItem>

                <controls:PivotItem x:Name="pvGraphs" Header="{Binding Path=L.Graphs, Source={StaticResource L}}">
                    <Grid>
                        <my:LenderGraphsControl x:Name="lenderGraphsControl" 
                                            Visibility="{Binding Lender.LoanCount, Converter={StaticResource numberVisibility}}"
                                            />
                        <my:NoLoansControl x:Name="noLoansControl2" 
                                    Visibility="{Binding Lender.LoanCount, Converter={StaticResource numberNotVisibility}}"/>
                    </Grid>
                </controls:PivotItem>

            </KCtl:OrientedPivot>
        </Grid>
    </Grid>

    <!--http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/03/27/windows-phone-7-series-icon-pack.aspx-->
    <KCtl:Bindable.ApplicationBar>
        <KCtl:BindableApplicationBar IsVisible="True" IsMenuEnabled="True" >

        </KCtl:BindableApplicationBar>
    </KCtl:Bindable.ApplicationBar>

</KCtl:BasePhoneApplicationPage>